-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: bash shell for production docker builds #6469
base: master
Are you sure you want to change the base?
build: bash shell for production docker builds #6469
Conversation
eef9b5c
to
cf7f63f
Compare
@@ -27,7 +27,7 @@ docker compose up -d | |||
# stop the local services when you're finished | |||
docker compose down | |||
# run the tests | |||
docker compose run --rm project test | |||
docker compose run --rm root test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo. The Next.js app service is called root
in docker-compose.yml
.
docker-compose.yml
Outdated
prod-shell: | ||
image: front-end-monorepo_prod:latest | ||
build: | ||
context: ./ | ||
args: | ||
- NODE_ENV=production | ||
- PANOPTES_ENV=production | ||
- NEXT_TELEMETRY_DISABLED=1 | ||
- APP_ENV=development | ||
command: | ||
- "/bin/sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs bin/sh
inside the front-end-monorepo_prod
container, giving you a bash shell so that you can poke around the file system and debug the production build.
dev-shell
does the same thing for front-end-monorepo_dev
, which has dev dependencies installed (so you can also run tests from that shell.)
image: front-end-monorepo_dev:latest | ||
volumes: | ||
- node_modules:/usr/src/node_modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this to make it easier to debug the node package installs. Otherwise, you're just looking at the I'm going to avoid changes to existing services here. Just add a new service for the production bash shell, and rename the existing service (and volume.)node_modules
directory from your local machine.
Here's the output of front-end-monorepo % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
front-end-monorepo_prod latest 26d2798ccb75 33 minutes ago 1.43GB
front-end-monorepo_dev latest 0c20a73cd0f3 35 minutes ago 2.07GB |
2640253
to
5321a95
Compare
- node_modules:/usr/src/node_modules | ||
volumes: | ||
node_modules: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added two node_modules
volumes, so you can compare production vs. development installs in Docker Desktop.
870783f
to
7a72e98
Compare
This adds a bash shell for production docker builds, and renames the previous `shell` service to `dev-shell`.
7a72e98
to
0f24ff5
Compare
- Add the lockfile last, so that previous layers are cached. - Copy files from the builder to the production app runner.
@@ -40,6 +38,8 @@ ADD lerna.json /usr/src/ | |||
|
|||
COPY ./packages /usr/src/packages | |||
|
|||
ADD yarn.lock /usr/src/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yarn.lock
changes quite frequently, so should be added to the image after all other files.
COPY --from=builder /usr/src/package.json /usr/src/package.json | ||
|
||
COPY .yarn /usr/src/.yarn | ||
COPY --from=builder /usr/src/.yarn /usr/src/.yarn | ||
|
||
ADD .yarnrc /usr/src/ | ||
COPY --from=builder /usr/src/.yarnrc /usr/src/.yarnrc | ||
|
||
COPY --from=builder /usr/src/packages ./packages | ||
|
||
COPY --from=builder /usr/src/yarn.lock /usr/src/yarn.lock | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything that the production runner uses should be copied from the builder image.
This adds a bash shell for production docker builds, and renames the previous
shell
service todev-shell
.It also optimises the Dockerfile for faster builds.
Please request review from
@zooniverse/frontend
team or an individual member of that team.Linked Issue and/or Talk Post
How to Review
Similar to #6465, but with the changes here you should be able to get CLI shells into both production and dev installs of the monorepo:
I've been using these to run
du -sh *
inside a production build, and have a look at how big each directory is.When I run
ls node_modules
inside the production container, I don't see@storybook
,mocha
orwebpack
, so I think the production Yarn install is working, and only installing production dependencies. This might be useful for checking whether that's still true after moving to Yarn 4.You should also be able to inspect the
node_modules-dev
andnode_modules-prod
volumes in Docker Desktop, to see the difference between production and development images.Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expected